package cqu.java.lock;

public class Run {
	public static void main(String[] args) {
		new Run().befin();
	}
	
	public void befin() {
		MyService myService = new MyService();
		ThreadA threadA = new ThreadA(myService);
		threadA.setName("A");
		threadA.start();
		
		ThreadB threadB = new ThreadB(myService);
		threadB.setName("B");
		threadB.start();
		
		myService.waitC();
		
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		myService.signalAll();
	}
	
	class ThreadA extends Thread{
		private MyService myService;

		public ThreadA(MyService myService) {
			super();
			this.myService = myService;
		}
		
		@Override
		public void run() {
			super.run();
			myService.awaintA();
		}
	}
	
	class ThreadB extends Thread{
		private MyService myService;

		public ThreadB(MyService myService) {
			super();
			this.myService = myService;
		}
		
		@Override
		public void run() {
			// TODO Auto-generated method stub
			super.run();
			myService.awaintB();
		}
	}
}
